//
//  ProductTableViewCell.m
//  CMVRFForIOS
//
//  Created by zhangnorman on 15/5/29.
//  Copyright (c) 2015年 hvacapp. All rights reserved.
//

#import "ProductTableViewCell.h"

@interface ProductTableViewCell ()

@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *xlLabel;
@property (nonatomic,strong) UILabel *xsLabel;

@end

@implementation ProductTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    return self;
}

/**
 *  <#Description#>
 */
- (void)setupViews {
    self.contentView.width = kScreen_Width;
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(CELL_PADDING_LEFT, CELL_PADDING_TOP, kScreen_Width - CELL_PADDING_RIGHT - 2*CELL_PADDING_LEFT, kListTitleFontSize)];
    self.titleLabel.font = [UIFont systemFontOfSize:kListTitleFontSize];
    self.titleLabel.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.titleLabel];
    
    self.xlLabel = [[UILabel alloc]initWithFrame:CGRectMake(2*CELL_PADDING_LEFT, CGRectGetMaxY(self.titleLabel.frame) + CELL_PADDING_TOP, kScreen_Width - CELL_PADDING_RIGHT - 3*CELL_PADDING_LEFT, kListDetailFontSize)];
    self.xlLabel.font = [UIFont systemFontOfSize:kListDetailFontSize];
    self.xlLabel.textColor = CM_TABLE_DETAIL_COLOR;
    [self.contentView addSubview:self.xlLabel];
    
    self.xsLabel = [[UILabel alloc]initWithFrame:CGRectMake(2*CELL_PADDING_LEFT, CGRectGetMaxY(self.xlLabel.frame) + CELL_PADDING_TOP, kScreen_Width - CELL_PADDING_RIGHT - 3*CELL_PADDING_LEFT, kListDetailFontSize)];
    self.xsLabel.font = [UIFont systemFontOfSize:kListDetailFontSize];
    self.xsLabel.textColor = CM_TABLE_DETAIL_COLOR;
    [self.contentView addSubview:self.xsLabel];
}

- (void)setProductTitle:(NSString*)title andXl:(NSString*)xl andXs:(NSString*)xs {
    self.titleLabel.text = title;
    
    if (![xl isKindOfClass:[NSNull class]] && ![xl isEmpty]) {
        self.xlLabel.hidden = NO;
        self.xlLabel.text = [NSString stringWithFormat:@"系列：%@", xl];
    }
    else {
        self.xlLabel.hidden = YES;
        self.xsLabel.y = CGRectGetMaxY(self.titleLabel.frame) + CELL_PADDING_TOP;
    }
    
    if (![xs isKindOfClass:[NSNull class]] && ![xs isEmpty]) {
        self.xsLabel.hidden = NO;
        self.xsLabel.text = [NSString stringWithFormat:@"型式：%@", xs];
    }
    else {
        self.xsLabel.hidden = YES;
    }
}

- (CGFloat)getHeight:(BOOL)hasXl andXs:(BOOL)hasXs{
    if (hasXl&&hasXs) {
        return CGRectGetMaxY(self.xsLabel.frame) + CELL_PADDING_BOTTOM;
    }
    else if(hasXl) {
        return CGRectGetMaxY(self.xlLabel.frame) + CELL_PADDING_BOTTOM;
    }
    else if(hasXs){
        return CGRectGetMaxY(self.xlLabel.frame) + CELL_PADDING_BOTTOM;
    }
    else {
        return CGRectGetMaxY(self.titleLabel.frame) + CELL_PADDING_BOTTOM;
    }
}

@end
